﻿using SimpleFactory.Interface;
using SimpleFactory.Service;
using System;

namespace SimpleFactory
{
    /// <summary>
    /// 简单工厂模式
    /// </summary>
    public class Program
    {
        static void Main(string[] args)
        {
            #region 上端完全依赖下端且知道细节
            {
                Human human = new Human();
                human.ShowKing();

                NE nE = new NE();
                nE.ShowKing();

                ORC oRC = new ORC();
                oRC.ShowKing();

                Undead undead = new Undead();
                undead.ShowKing();
            }
            #endregion

            #region 左边换成抽象，依赖倒置原则
            {
                IRace race = new Human();
                race.ShowKing();
            }
            #endregion

            #region 上端通过调用工厂类，传入参数创建实例
            {
                IRace race = ObjectFactory.CreateInstance(RaceType.Human);
                race.ShowKing();
            }
            #endregion

            #region 上端玩家抽象+下端种族抽象
            {
                Player player = new Player()
                {
                    Id = 123,
                    Name = "mage"
                };

                //如此调用不利于种族的扩展
                Human human = new Human(); 
                player.PlayHuman(human);

                //上端抽象玩家，下端抽象了种族，并将对象创建交给工厂类
                IRace race2 = ObjectFactory.CreateInstance(RaceType.Human);
                player.Play(race2);

            }
            #endregion

            #region 通过配置文件的方式创建对象
            {
                Player player = new Player()
                {
                    Id = 123,
                    Name = "mage"
                };
                //可配置
                Console.WriteLine("*****************Factory+Config***************");
                IRace race = ObjectFactory.CreateInstanceConfig();
                player.Play(race);
            }
            #endregion

            #region 反射+配置文件的方式创建对象
            {
                Player player = new Player()
                {
                    Id = 123,
                    Name = "mage"
                };
                //可配置
                Console.WriteLine("*****************Factory+Config***************");
                IRace race = ObjectFactory.CreateInstanceConfigReflection();
                player.Play(race);
            }
            #endregion
        }
    }
}
